Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build with boost ASIO 1.87. Support boost 1.66+ #9628

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vtnerd
Copy link
Contributor

@vtnerd vtnerd commented Dec 17, 2024

This should compile with Boost 1.73-1.87. I have only tested on Boost 1.74 and Boost 1.87 (primarily unit tests). I will mark the places where I know changes need to be made for older boost versions. I will clear up all such errors by manually downloading Boost 1.66 and testing.

One problem I have with supporting Boost 1.66-1.69 is that most types require an io_context object, whereas Boost 1.70+ have relaxed this requirement to an executor object. I will show an example of where it matters; it will be easy to break older Boost versions unintentionally.

EDIT:
This is currently marked as a draft, because the depends build will fail until #9162 gets merged (which is also marked as draft).

contrib/epee/include/net/abstract_tcp_server2.inl Outdated Show resolved Hide resolved
contrib/epee/src/net_ssl.cpp Outdated Show resolved Hide resolved
contrib/epee/src/net_helper.cpp Outdated Show resolved Hide resolved
@tobtoht
Copy link
Contributor

tobtoht commented Dec 17, 2024

(This needs #9162 to pass depends CI. I will undraft that PR after the next round of merges.)

@vtnerd vtnerd force-pushed the fix/boost_1.87_squashed branch from 8c98c45 to e88e61d Compare December 18, 2024 02:51
@vtnerd
Copy link
Contributor Author

vtnerd commented Dec 18, 2024

The latest force push should work with Boost 1.66-1.87. Something funky happened with the tests, so I may push a dummy change later to see what happens.

@tobtoht
Copy link
Contributor

tobtoht commented Dec 18, 2024

https://github.com/tobtoht/monero/actions/runs/12390979989/job/34587144842#step:5:1281

Looks like boost::asio::io_service is also used in src/device_trezor/trezor.

@vtnerd
Copy link
Contributor Author

vtnerd commented Dec 20, 2024

Fore pushed some changes:

  • Reverted changes to query code, they are basically same style with new interface
  • Switched to io_context_t as @jeffro256 suggested
  • Fixed Trezor build.

@vtnerd vtnerd force-pushed the fix/boost_1.87_squashed branch 2 times, most recently from 1c62d08 to da62d98 Compare December 20, 2024 19:22
@vtnerd
Copy link
Contributor Author

vtnerd commented Dec 20, 2024

Force pushed twice with updates:

  • Added a missing include, but it doesn't matter as the depends builds is using Boost 1.64 which won't work
  • Reverted some whitespace changes that were made when making the patch.

@vtnerd vtnerd force-pushed the fix/boost_1.87_squashed branch from da62d98 to a0ce1e9 Compare December 20, 2024 19:38
@vtnerd
Copy link
Contributor Author

vtnerd commented Dec 20, 2024

Force pushed an include fix.

@vtnerd
Copy link
Contributor Author

vtnerd commented Dec 20, 2024

This patch looks ready. The depends CI will all fail until #9162 gets merged. I will leave as draft for now for that reason.

Copy link
Collaborator

@selsta selsta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README needs an update to indicate the new minimum version

@0xFFFC0000
Copy link
Collaborator

Once this is ready for review, please remove Draft status.

@vtnerd vtnerd force-pushed the fix/boost_1.87_squashed branch 2 times, most recently from 625f370 to 0452910 Compare December 25, 2024 23:17
@vtnerd
Copy link
Contributor Author

vtnerd commented Dec 25, 2024

Force pushed:

Likely this will get removed as draft, assuming some of the tests cycle green.

@vtnerd vtnerd force-pushed the fix/boost_1.87_squashed branch from 0452910 to ad7eaaa Compare December 25, 2024 23:45
@vtnerd
Copy link
Contributor Author

vtnerd commented Dec 25, 2024

README needs an update to indicate the new minimum version

Forgot to update this in the last force push, so another quick push with this change.

@vtnerd vtnerd marked this pull request as ready for review December 26, 2024 14:19
@vtnerd
Copy link
Contributor Author

vtnerd commented Dec 26, 2024

Now ready for review.

@jeffro256
Copy link
Contributor

Getting a ton of build errors across many platforms:

fatal error: boost/asio/io_context.hpp: No such file or directory

@jeffro256
Copy link
Contributor

jeffro256 commented Dec 27, 2024

The dependencies system seems to still be pulling Boost 1.64 instead of 1.66 on these failed platforms

@selsta
Copy link
Collaborator

selsta commented Dec 27, 2024

@jeffro256 requires #9162 to be merged first

@jeffro256
Copy link
Contributor

Sorry, my bad. Should've read farther up in the comments

Copy link
Collaborator

@0xFFFC0000 0xFFFC0000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From technical perspective, everything is great, and I don't see any specific issues.

The only remaining thing is I have to fetch #9162 and compile, and run all the tests.

Copy link
Contributor

@jeffro256 jeffro256 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple actual comments, but mostly nitpicks

using io_context_t = boost::asio::io_service;
using strand_t = boost::asio::io_service::strand;
using io_context_t = boost::asio::io_context;
using strand_t = boost::asio::io_context::strand;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using strand_t = boost::asio::io_context::strand;
using strand_t = io_context_t::strand;

@@ -306,7 +308,7 @@ namespace net_utils
virtual bool close();
virtual bool call_run_once_service_io();
virtual bool request_callback();
virtual boost::asio::io_service& get_io_service();
virtual boost::asio::io_context& get_io_context();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
virtual boost::asio::io_context& get_io_context();
virtual io_context_t& get_io_context();

@@ -1767,7 +1776,7 @@ namespace net_utils
if (r)
{
new_connection_l->get_context(conn_context);
//new_connection_l.reset(new connection<t_protocol_handler>(io_service_, m_config, m_sock_count, m_pfilter));
//new_connection_l.reset(new connection<t_protocol_handler>(io_context_, m_config, m_sock_count, m_pfilter));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just remove this line?

try
{
//resolving ipv4 address as ipv6 throws, catch here and move on
iterator = resolver.resolve(query, resolve_error);
results = resolver.resolve(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove DNS resolution from this function completely. This is supposed to be an async function, but this DNS call is not async, which I'm sure degrades the performance of the main I/O loop. Also, the one place in the codebase that calls connect_async() (p2p) I think is calling it with raw IPv4 and IPv6 addresses, so it shouldn't even need DNS resolution.

try
{
//resolving ipv4 address as ipv6 throws, catch here and move on
iterator = resolver.resolve(query, resolve_error);
results = resolver.resolve(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here as other comment: the one place this is called, we use raw IP addresses

@@ -32,7 +32,7 @@

#include <atomic>

#include <boost/asio/io_service.hpp>
#include <boost/asio/io_context.hpp>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this header include even be here in the first place?

m_want_close_connection(false),
m_was_shutdown(false),
m_is_multithreaded(false),
m_ssl_support(ssl_support)
{
// add nullptr checks if removed
assert(m_state != nullptr); // release runtime check in get_context
assert(m_state != nullptr); // release runtime check in get_contextp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo?


socket_.next_layer() = std::move(sock);
socket_.next_layer() = std::move(sock);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's happening with the whitespace here?

results = resolver.resolve(
boost::asio::ip::tcp::v6(), addr, port, boost::asio::ip::tcp::resolver::canonical_name
);
if (results.empty())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this overload of resolve() shouldn't ever return an empty range because otherwise, it will throw a boost exception. That would make this if branch unreachable.

throw boost::system::system_error{boost::asio::error::fault, "Failed to resolve " + addr};
}

//////////////////////////////////////////////////////////////////////////

struct new_connection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the move of this struct declaration purely for readability purposes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants